//
// Copyright (c) 2009-2011, chunquedong
//
// This file is part of ChunMap project
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
//
// History:
//   2011-05-02  Jed Young  Creation
//

internal class ValidTest : Test
{
  WktReader wkt := WktReader()

  Void testIsValid()
  {
    g := wkt.read("POLYGON((1.8000000000000114 -2.0000000000000284,10.800000000000011 -2.0000000000000284,10.800000000000011 6.999999999999972,1.8000000000000114 6.999999999999972,1.8000000000000114 -2.0000000000000284))")
    verify(g.isValid)
  }

  Void testIsValid2()
  {
    g := wkt.read("MULTILINESTRING((-5.0 -8.0,10.0 -20.0,20.0 15.0,-10.0 10.0,-5.0 -8.0),(1.0 2.0,3.0 1.0,4.0 0.0,3.0 -2.0,0.0 0.0,1.0 2.0))")
    verify(g.isValid)
  }

  Void testIsValid3()
  {
    g := wkt.read("POLYGON((-2.639991350383829 -1.6999950537374091,-1.8399918576928131 -1.6999950537374091,-1.8399918576928131 -1.8999950537374093,-2.639991350383829 -1.8999950537374093,-2.639991350383829 -1.8999699747124392,-2.6707263850912843 -1.8951546966619783,-2.6986151503008315 -1.881008941949809,-2.7207711785272037 -1.8589409557588967,-2.7350278636719665 -1.8311087346837973,-2.7399910650226005 -1.8002339515486374,-2.735175438265397 -1.7693358069404994,-2.7210518966070625 -1.741435785931271,-2.699001560850286 -1.7192621914030142,-2.6711807015790856 -1.7049833472375313,-2.639991350383829 -1.6999950537374091,-2.639991350383829 -1.6999950537374091))")
    verify(!g.isValid)
  }

  Void testIsValid4()
  {
    g := wkt.read("LINESTRING(-2.7350278636719665 -1.8311087346837973,-2.7399910650226005 -1.8002339515486374,-2.739953831631839 -1.7999950537374083,-2.7399910650226005 -1.8002339515486374,-2.7350278636719665 -1.8311087346837973,-2.7207711785272037 -1.8589409557588967,-2.6986151503008315 -1.881008941949809,-2.7207711785272037 -1.8589409557588967,-2.7350278636719665 -1.8311087346837973)")
    verify(!g.isValid)
  }

  Void testIsValid5()
  {
    g := wkt.read("POLYGON((-1.7400044304807296 -1.7999950537374092,-1.7448567200694303 -1.8308058568652084,-1.7590246788650967 -1.8586833485897951,-1.7811103014960337 -1.8808217964643401,-1.8089538667256089 -1.8950563135477008,-1.8398325924011645 -1.8999949269101633,-1.8399918576928131 -1.8999699747124394,-1.8399918576928131 -1.8999950537374093,-2.639991350383829 -1.8999950537374093,-2.639991350383829 -1.8999699747124392,-2.6707263850912843 -1.8951546966619783,-2.6986151503008315 -1.881008941949809,-2.7207711785272037 -1.8589409557588967,-2.7350278636719665 -1.8311087346837973,-2.7399910650226005 -1.8002339515486374,-2.735175438265397 -1.7693358069404994,-2.7210518966070625 -1.741435785931271,-2.699001560850286 -1.7192621914030142,-2.6711807015790856 -1.7049833472375313,-2.639991350383829 -1.6999950537374091,-1.8399918576928131 -1.6999950537374091,-1.8091053056829198 -1.7048844817438598,-1.781239105121424 -1.719074635638606,-1.7591182516375001 -1.7411778807042717,-1.7449059116421661 -1.7690327724317068,-1.7399918893996298 -1.799915421066336,-1.739991857692813 -1.7999950537374092,-1.739991857692813 -0.9999955610463935,-1.9399918576928132 -0.9999955610463935,-1.9399918576928132 -1.7999950537374092,-1.7400044304807296 -1.7999950537374092))")
    verify(!g.isValid)
  }

//////////////////////////////////////////////////////////////////////////
//lineStringValid
//////////////////////////////////////////////////////////////////////////

  Void testIsSimple()
  {
    p1 := Coord(10f, 20f)
    p3 := Coord(30f, 60f)
    p5 := Coord(50f, 100f)

    points := Point[p1, p3, p5]

    ls := LineString.makePoints(points)
    verify(ls.isValid)
  }

  Void testIsSimple2()
  {
    p1 := Coord(10f, 20f)
    p2 := Coord(20f, 40f)
    p3 := Coord(30f, 60f)
    p5 := Coord(50f, 100f)

    points := Point[p1, p3, p5, p2]

    ls := LineString.makePoints(points)
    verify(!ls.isValid)
  }

  Void testIsSimple4()
  {
    p1 := Coord(1f, 1f)
    p2 := Coord(1f, 2f)
    p3 := Coord(3f, 2f)
    p4 := Coord(4f, 0f)

    points := Point[p3, p1, p2, p3, p4]

    ls := LineString.makePoints(points)
    verify(ls.isValid)
  }
}